// 连接mongodb
const mongoose = require('mongoose')

const url = 'mongodb://localhost:27017'
const dataBase = 'blog'
mongoose
  .connect(`${url}/${dataBase}`)
  .then((res) => {
    console.log('mongodb connected success')
  })
  .catch((err) => {
    console.error('connection error' + err)
  })

const db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error:'))

module.exports = {
  mongoose,
}
